<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../resources/get-host-info.js"></script>
<script src="resources/load_wasm.js"></script>
<script>
promise_test(async function() {
  var remote_loc = get_host_info().AUTHENTICATED_ORIGIN + "/wasm/resources/remote_frame.html";
  var mod = await createWasmModule();
  assert_true(mod instanceof WebAssembly.Module);
  var remote;
  await new Promise((resolve, reject) => {
    var nr_of_tries = 0;
    var i = setInterval(()=>{
      try {
        remote.document;
        ++nr_of_tries;
        if(nr_of_tries > 30) {
          reject();
        }
      } catch(e) {
        clearInterval(i);
        resolve();
      }
    }, 1000);
    remote = window.open("about:blank");
    remote.opener = null;
    remote.location = remote_loc;
  });
  var ans = await new Promise((resolve, reject) => {
  remote.postMessage(mod, '*');
  window.addEventListener("message",
     function f(reply) {
       resolve(reply.data);
       window.removeEventListener("message", f);
     }, false);
  });
  assert_equals(ans, "didn't make it");
  ans = await new Promise((resolve, reject) => {
    remote.postMessage("hi!", '*');
    window.addEventListener("message", (reply) => resolve(reply.data), false);
  });
  assert_equals(ans, "hi!");
}, "cannot send wasm module to remote iframe");
</script>
